home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / cg.lha / cg / m2c / Tree2.c < prev    next >
C/C++ Source or Header  |  1992-11-24  |  6KB  |  321 lines

  1. #include "SYSTEM_.h"
  2.  
  3. #ifndef DEFINITION_System
  4. #include "System.h"
  5. #endif
  6.  
  7. #ifndef DEFINITION_General
  8. #include "General.h"
  9. #endif
  10.  
  11. #ifndef DEFINITION_Memory
  12. #include "Memory.h"
  13. #endif
  14.  
  15. #ifndef DEFINITION_DynArray
  16. #include "DynArray.h"
  17. #endif
  18.  
  19. #ifndef DEFINITION_IO
  20. #include "IO.h"
  21. #endif
  22.  
  23. #ifndef DEFINITION_Layout
  24. #include "Layout.h"
  25. #endif
  26.  
  27. #ifndef DEFINITION_StringMem
  28. #include "StringMem.h"
  29. #endif
  30.  
  31. #ifndef DEFINITION_Strings
  32. #include "Strings.h"
  33. #endif
  34.  
  35. #ifndef DEFINITION_Idents
  36. #include "Idents.h"
  37. #endif
  38.  
  39. #ifndef DEFINITION_Texts
  40. #include "Texts.h"
  41. #endif
  42.  
  43. #ifndef DEFINITION_Sets
  44. #include "Sets.h"
  45. #endif
  46.  
  47. #ifndef DEFINITION_Positions
  48. #include "Positions.h"
  49. #endif
  50.  
  51. #ifndef DEFINITION_Tree
  52. #include "Tree.h"
  53. #endif
  54.  
  55. #ifndef DEFINITION_Tree2
  56. #include "Tree2.h"
  57. #endif
  58.  
  59.  
  60. typedef Tree_tTree *yyPtrtTree;
  61. static IO_tFile yyf;
  62. static SHORTCARD yyLabel;
  63. static SHORTCARD yyKind;
  64. static CHAR yyc;
  65. static Strings_tString yys;
  66. static void yyMark ARGS((Tree_tTree yyt));
  67. #define yyInitTreeStoreSize    32
  68. static LONGINT yyTreeStoreSize;
  69. static struct S_1 {
  70.     Tree_tTree A[50000 + 1];
  71. } *yyTreeStorePtr;
  72. static INTEGER yyLabelCount;
  73. static SHORTINT yyRecursionLevel;
  74. static SHORTCARD yyMapToLabel ARGS((Tree_tTree yyTree));
  75. static Tree_tTree yyMapToTree ARGS((SHORTCARD yyLabel));
  76. #define yyNil    ((CHAR)'\374')
  77. #define yyNoLabel    ((CHAR)'\375')
  78. #define yyLabelDef    ((CHAR)'\376')
  79. #define yyLabelUse    ((CHAR)'\377')
  80. static void yyPutTree2 ARGS((Tree_tTree yyt));
  81. static void yyPut ARGS((BYTE yyx[], LONGCARD ));
  82. static void yyPutIdent ARGS((Idents_tIdent yyi));
  83.  
  84.  
  85. static void yyMark
  86. # ifdef __STDC__
  87. (Tree_tTree yyt)
  88. # else
  89. (yyt)
  90. Tree_tTree yyt;
  91. # endif
  92. {
  93.   for (;;) {
  94.     if (yyt == Tree_NoTree) {
  95.       return;
  96.     }
  97.     INC(yyt->U_1.V_2.yyHead.yyMark);
  98.     if (yyt->U_1.V_2.yyHead.yyMark > 1) {
  99.       return;
  100.     }
  101.     switch (yyt->U_1.V_1.Kind) {
  102.     case Tree_Class:;
  103.       yyMark(yyt->U_1.V_5.Class.Attributes);
  104.       yyMark(yyt->U_1.V_5.Class.Extensions);
  105.       yyMark(yyt->U_1.V_5.Class.BaseClass);
  106.       yyt = yyt->U_1.V_5.Class.Next;
  107.       break;
  108.     case Tree_AttrOrAction:;
  109.       yyt = yyt->U_1.V_8.AttrOrAction.Next;
  110.       break;
  111.     case Tree_Child:;
  112.       yyt = yyt->U_1.V_9.Child.Next;
  113.       break;
  114.     case Tree_Attribute:;
  115.       yyt = yyt->U_1.V_10.Attribute.Next;
  116.       break;
  117.     case Tree_ActionPart:;
  118.       yyt = yyt->U_1.V_11.ActionPart.Next;
  119.       break;
  120.     default :
  121.       return;
  122.       break;
  123.     }
  124.   } EXIT_1:;
  125. }
  126.  
  127. static SHORTCARD yyMapToLabel
  128. # ifdef __STDC__
  129. (Tree_tTree yyTree)
  130. # else
  131. (yyTree)
  132. Tree_tTree yyTree;
  133. # endif
  134. {
  135.   INTEGER yyi;
  136.  
  137.   {
  138.     LONGINT B_1 = 1, B_2 = yyLabelCount;
  139.  
  140.     if (B_1 <= B_2)
  141.       for (yyi = B_1;; yyi += 1) {
  142.         if (yyTreeStorePtr->A[yyi] == yyTree) {
  143.           return yyi;
  144.         }
  145.         if (yyi >= B_2) break;
  146.       }
  147.   }
  148.   INC(yyLabelCount);
  149.   if (yyLabelCount == yyTreeStoreSize) {
  150.     DynArray_ExtendArray((ADDRESS *)&yyTreeStorePtr, &yyTreeStoreSize, (LONGINT)sizeof(Tree_tTree));
  151.   }
  152.   yyTreeStorePtr->A[yyLabelCount] = yyTree;
  153.   return yyLabelCount;
  154. }
  155.  
  156. static Tree_tTree yyMapToTree
  157. # ifdef __STDC__
  158. (SHORTCARD yyLabel)
  159. # else
  160. (yyLabel)
  161. SHORTCARD yyLabel;
  162. # endif
  163. {
  164.   return yyTreeStorePtr->A[yyLabel];
  165. }
  166.  
  167. void Tree2_PutTree2
  168. # ifdef __STDC__
  169. (IO_tFile yyyf, Tree_tTree yyt)
  170. # else
  171. (yyyf, yyt)
  172. IO_tFile yyyf;
  173. Tree_tTree yyt;
  174. # endif
  175. {
  176.   yyf = yyyf;
  177.   if (yyRecursionLevel == 0) {
  178.     yyLabelCount = 0;
  179.   }
  180.   INC(yyRecursionLevel);
  181.   yyMark(yyt);
  182.   yyPutTree2(yyt);
  183.   DEC(yyRecursionLevel);
  184. }
  185.  
  186. static void yyPutTree2
  187. # ifdef __STDC__
  188. (Tree_tTree yyt)
  189. # else
  190. (yyt)
  191. Tree_tTree yyt;
  192. # endif
  193. {
  194.   for (;;) {
  195.     if (yyt == Tree_NoTree) {
  196.       IO_WriteC(yyf, yyNil);
  197.       return;
  198.     } else if (yyt->U_1.V_2.yyHead.yyMark == 0) {
  199.       IO_WriteC(yyf, yyLabelUse);
  200.       yyLabel = yyMapToLabel(yyt);
  201.       yyPut((WORD *)&yyLabel, (LONGCARD)sizeof(yyLabel));
  202.       return;
  203.     } else if (yyt->U_1.V_2.yyHead.yyMark > 1) {
  204.       IO_WriteC(yyf, yyLabelDef);
  205.       yyLabel = yyMapToLabel(yyt);
  206.       yyPut((WORD *)&yyLabel, (LONGCARD)sizeof(yyLabel));
  207.       IO_WriteC(yyf, CHR(yyt->U_1.V_1.Kind));
  208.     } else {
  209.       IO_WriteC(yyf, CHR(yyt->U_1.V_1.Kind));
  210.     }
  211.     yyt->U_1.V_2.yyHead.yyMark = 0;
  212.     switch (yyt->U_1.V_1.Kind) {
  213.     case Tree_Class:;
  214.       yyPutIdent(yyt->U_1.V_5.Class.Name);
  215.       yyPut((WORD *)&yyt->U_1.V_5.Class.Properties, (LONGCARD)sizeof(yyt->U_1.V_5.Class.Properties));
  216.       yyPutTree2(yyt->U_1.V_5.Class.Attributes);
  217.       yyPutTree2(yyt->U_1.V_5.Class.Extensions);
  218.       yyPutTree2(yyt->U_1.V_5.Class.BaseClass);
  219.       yyt = yyt->U_1.V_5.Class.Next;
  220.       break;
  221.     case Tree_AttrOrAction:;
  222.       yyt = yyt->U_1.V_8.AttrOrAction.Next;
  223.       break;
  224.     case Tree_Child:;
  225.       yyPutIdent(yyt->U_1.V_9.Child.Name);
  226.       yyPutIdent(yyt->U_1.V_9.Child.Type);
  227.       yyPut((WORD *)&yyt->U_1.V_9.Child.Properties, (LONGCARD)sizeof(yyt->U_1.V_9.Child.Properties));
  228.       yyt = yyt->U_1.V_9.Child.Next;
  229.       break;
  230.     case Tree_Attribute:;
  231.       yyPutIdent(yyt->U_1.V_10.Attribute.Name);
  232.       yyPutIdent(yyt->U_1.V_10.Attribute.Type);
  233.       yyPut((WORD *)&yyt->U_1.V_10.Attribute.Properties, (LONGCARD)sizeof(yyt->U_1.V_10.Attribute.Properties));
  234.       yyt = yyt->U_1.V_10.Attribute.Next;
  235.       break;
  236.     case Tree_ActionPart:;
  237.       yyt = yyt->U_1.V_11.ActionPart.Next;
  238.       break;
  239.     default :
  240.       return;
  241.       break;
  242.     }
  243.   } EXIT_2:;
  244. }
  245.  
  246. static void yyPut
  247. # ifdef __STDC__
  248. (BYTE yyx[], LONGCARD O_1)
  249. # else
  250. (yyx, O_1)
  251. BYTE yyx[];
  252. LONGCARD O_1;
  253. # endif
  254. {
  255.   INTEGER yyi;
  256.  
  257.   yyi = IO_Write(yyf, ADR1(yyx), (INTEGER)(O_1 - 1) + 1);
  258. }
  259.  
  260. static void yyPutIdent
  261. # ifdef __STDC__
  262. (Idents_tIdent yyi)
  263. # else
  264. (yyi)
  265. Idents_tIdent yyi;
  266. # endif
  267. {
  268.   Strings_tString yys;
  269.  
  270.   Idents_GetString(yyi, &yys);
  271.   Strings_WriteL(yyf, &yys);
  272. }
  273.  
  274. void Tree2_BeginTree2
  275. # ifdef __STDC__
  276. ()
  277. # else
  278. ()
  279. # endif
  280. {
  281. }
  282.  
  283. void Tree2_CloseTree2
  284. # ifdef __STDC__
  285. ()
  286. # else
  287. ()
  288. # endif
  289. {
  290. }
  291.  
  292. void BEGIN_Tree2()
  293. {
  294.   static BOOLEAN has_been_called = FALSE;
  295.  
  296.   if (!has_been_called) {
  297.     has_been_called = TRUE;
  298.  
  299.     BEGIN_Tree();
  300.     BEGIN_IO();
  301.     BEGIN_System();
  302.     BEGIN_General();
  303.     BEGIN_Memory();
  304.     BEGIN_DynArray();
  305.     BEGIN_IO();
  306.     BEGIN_Layout();
  307.     BEGIN_StringMem();
  308.     BEGIN_Strings();
  309.     BEGIN_Idents();
  310.     BEGIN_Texts();
  311.     BEGIN_Sets();
  312.     BEGIN_Positions();
  313.     BEGIN_Tree();
  314.  
  315.     yyRecursionLevel = 0;
  316.     yyTreeStoreSize = yyInitTreeStoreSize;
  317.     DynArray_MakeArray((ADDRESS *)&yyTreeStorePtr, &yyTreeStoreSize, (LONGINT)sizeof(Tree_tTree));
  318.     Tree2_BeginTree2();
  319.   }
  320. }
  321.